package com.juyu.miliao.api.controller.activity;

import com.juyu.miliao.api.domain.vo.*;
import com.juyu.miliao.api.service.CoolSummerActivitiesService;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.exception.ConsumeRuntimeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xuanqicheng
 */
@RestController
@RequestMapping("/coolSummer")
public class CoolSummerActivitiesController {

    @Autowired
    private CoolSummerActivitiesService coolSummerActivitiesService;

    /**
     * 获取奖池
     */
    @GetMapping("/jackpot")
    public CoolSummerJackpotVO getJackpot() {
        CoolSummerJackpotVO coolSummerJackpotVO = coolSummerActivitiesService.getJackpot();
        return coolSummerJackpotVO;
    }

    /**
     * 奖励信息列表
     * @param token
     * @return
     */
    @GetMapping("/list")
    public CoolSummerActivitiesResultVO getCoolSummerActivitiesList(Authentication token) {
        Subject subject = (Subject) token.getPrincipal();
        return coolSummerActivitiesService.getCoolSummerActivitiesList(subject.getId());
    }

    /**
     * 领取奖励
     */
    @PostMapping("/rewards")
    public void getRewards(Authentication token, Integer activitiesId) {
        if(activitiesId == null){
            throw new ConsumeRuntimeException("activitiesId不为空");
        }
        Subject subject = (Subject) token.getPrincipal();
        coolSummerActivitiesService.getRewards(subject.getId(), activitiesId);
    }

    /**
     * 领取奖励日志
     * @param token
     * @return
     */
    @GetMapping("/log/{page}-{pageSize}")
    public List<ActivityRewardLogVO> getRewardsLog(Authentication token,@PathVariable("page") Integer page,
                                                   @PathVariable("pageSize") Integer pageSize) {

        if (page <= 0) {
            page = 1;
        }
        if (pageSize <= 0) {
            pageSize = 20;
        }
        Subject subject = (Subject) token.getPrincipal();
        return coolSummerActivitiesService.getRewardsLog(subject.getId(), 1,page,pageSize);
    }

    /**
     * 充值记录
     * @param token
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/rechargeAmount/log/{page}-{pageSize}")
    public List<CoolSummerRechargeAmountDetailVO> getCoolSummerRechargeAmountDetailList(Authentication token,
                                                                                        @PathVariable("page") Integer page,
                                                                                        @PathVariable("pageSize") Integer pageSize) {

        if (page <= 0) {
            page = 1;
        }
        if (pageSize <= 0) {
            pageSize = 20;
        }
        Subject subject = (Subject) token.getPrincipal();

        return coolSummerActivitiesService.getCoolSummerRechargeAmountDetailList(subject.getId(),page,pageSize);

    }

    /**
     * 排行榜
     * @param token
     * @return
     */
    @GetMapping("/ranking/list")
    public CoolSummerRankingResultVO getRankingList(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return coolSummerActivitiesService.getRankingList(subject.getId());
    }

}
